<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl" alt="">
          </div>
          <div class="icon-desc">{{item.desc}}</div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconlist: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      if (this.iconlist.length) {
        this.iconlist.forEach((item, index) => {
          const page = Math.floor(index / 8)
          if (!pages[page]) {
            pages[page] = []
          }
          pages[page].push(item)
        })
      }
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/variables.styl"
  @import "~styles/mixins.styl"
  .icons
    overflow: hidden
    height: 3.7rem
    /deep/ .swiper-container
      height: 100%
    .icon
      position: relative
      overflow: hidden
      float: left
      width: 25%
      height: 1.5rem
      padding-top: .1rem
      text-align: center
      .icon-img
        display: inline-block
        width: 1.1rem
        height: 1.1rem
        text-align: center
        .icon-img-content
          height: 100%
      .icon-desc
        font-size: .28rem
        line-height: 1.15
        color: $darkTxtColor
        ellipsis()

</style>
